#!/bin/bash
IBUPRO=/data/project/ibuflow/project
SERVER_IP="$(curl members.3322.org/dyndns/getip 2>/dev/null)"
FLAG=">>> # # # # # # # # # # # # # # # # # # # # # # # # # # # # # >>>"
if [ -z "$1" ] || [ -z "$2" ] ; then
    echo "Usage:$0 {Order number} [Order date]"
    exit 1
fi
order_number=$1
order_date=$2
last_month=$(date +%m -d '-32 day')
LOGDIR=( "$IBUPRO/web-flow-7070/logs/ibu" "$IBUPRO/web-flow-7071/logs/ibu" "$IBUPRO/server-recharge-12121/logs/ibu" "$IBUPRO/server-recharge-12122/logs/ibu")

for log in ${LOGDIR[@]}
do
    cd $log
    CMD=$(ls | egrep "$last_month-$order_date")
    for file in $CMD
    do
        grep --color -n -E $order_number $file
        if [ $? -eq 0 ] ; then
            echo -e "\n
\033[33m$FLAG\033[0m
\033[33m>>>\033[0m IBU-1                
\033[33m>>>\033[0m ServerIP:\033[31m $SERVER_IP \033[0m
\033[33m>>>\033[0m DirName:\033[31m $(pwd) \033[0m
\033[33m>>>\033[0m FileName:\033[31m $file \033[0m
\033[33m$FLAG\033[0m\n"
        #else
        #    echo -e "\033[33m>>>\033[0m FileName:\033[31m $file is not found.\033[0m"
        fi
    done
done
